// 订单Mapper
package com.heima.mapper;

import com.heima.entity.OrderInfo;
import com.heima.entity.SeckillOrder;
import org.apache.ibatis.annotations.*;

@Mapper
public interface OrderMapper {

    @Insert("INSERT INTO order_info(user_id, goods_id, goods_name, goods_count, goods_price, order_channel, status, create_date) " +
            "VALUES(#{userId}, #{goodsId}, #{goodsName}, #{goodsCount}, #{goodsPrice}, #{orderChannel}, #{status}, #{createDate})")
    @SelectKey(keyColumn = "id", keyProperty = "id", resultType = long.class, before = false, statement = "SELECT LAST_INSERT_ID()")
    long insert(OrderInfo orderInfo);

    @Insert("INSERT INTO seckill_order (user_id, order_id, goods_id) VALUES (#{userId}, #{orderId}, #{goodsId})")
    int insertSeckillOrder(SeckillOrder seckillOrder);

    @Select("SELECT * FROM seckill_order WHERE user_id = #{userId} AND goods_id = #{goodsId}")
    SeckillOrder getSeckillOrderByUserIdAndGoodsId(@Param("userId") long userId, @Param("goodsId") long goodsId);
}
